package com.example.jussi.uidemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    Button button;
    ImageView imageView;
    Boolean isCola;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) findViewById(R.id.button);
        imageView = (ImageView) findViewById(R.id.imageView);
        isCola = true;
    }

    public void change(View view){
        if(isCola){
            button.setText("显示可口可乐图片");
            imageView.setImageResource(R.drawable.pepsicola);
            Toast.makeText(MainActivity.this, "现在显示的是百事可乐图片",Toast.LENGTH_SHORT).show();
            isCola = false;
        }else{
            button.setText("显示百事可乐图片");
            imageView.setImageResource(R.drawable.cocacola);
            Toast.makeText(MainActivity.this, "现在显示的是可口可乐图片",Toast.LENGTH_SHORT).show();
            isCola = true;
        }
    }
}
